package com.xdf.zipperdye.controller;

import com.xdf.zipperdye.model.BillCp;
import com.xdf.zipperdye.service.BillCpService;
import com.xdf.zipperdye.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description = "成品单据")
@CrossOrigin
@RestController
@RequestMapping("/billCp")
public class BillCpController {
    @Autowired
    private BillCpService service;

    @ApiOperation(value="新增", notes="测试数据：{\"main\":{\"bill_type\":\"成品入库\",\"client_sid\":\"白玉兰\"},\"details\":[{\"goods_sid\":\"法兰绒\",\"amount\":\"10\"},{\"goods_sid\":\"珊瑚绒\",\"amount\":\"11\"}]}", produces="application/json")
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody BillCp billCp){
        return JsonResult.ok(service.insert(billCp));
    }

    @ApiOperation(value="修改", notes="测试数据：{\"main\":{\"iid\":\"1\",\"bill_type\":\"成品入库\",\"client_sid\":\"白玉兰1\"},\"details\":[{\"iid\":\"1\",\"parent_id\":\"1\",\"goods_sid\":\"法兰绒\",\"amount\":\"10\"},{\"iid\":\"2\",\"parent_id\":\"1\",\"goods_sid\":\"珊瑚绒\",\"amount\":\"13\"}]}", produces="application/json")
    @PostMapping("/update")
    public JsonResult update(@RequestBody BillCp billCp){
        return JsonResult.ok(service.update(billCp));
    }

    @ApiOperation(value="删除", notes="删除，将主键拼接在 url 后面：/delete/123", produces="application/json")
    @GetMapping("/delete/{id}")
    public JsonResult delete(@PathVariable Integer id){
        return JsonResult.ok(service.deleteByPrimaryKey(id));
    }

    @ApiOperation(value="根据单据编号查找", notes="将单据编号拼接在 url 后面：/selectByBillCode/单据编号", produces="application/json")
    @GetMapping("/selectByBillCode/{billCode}")
    public JsonResult selectByBillCode(@PathVariable String billCode){
        return JsonResult.ok(service.selectByBillCode(billCode));
    }

    @ApiOperation(value="根据主键查找", notes="将主键拼接在 url 后面：/selectByPrimaryKey/123", produces="application/json")
    @GetMapping("/selectByPrimaryKey/{id}")
    public  JsonResult selectByPrimaryKey(@PathVariable Integer id){
        return JsonResult.ok(service.selectByPrimaryKey(id));
    }

}
